/*
  Copyright © 2010  Rodrigo Peixoto
  Copyright © 2010  Camilo Costa Campos
  Copyright © 2010  Willian Victor Silva

      This file is part of Touché.

      Touché is free software: you can redistribute it and/or modify
      it under the terms of the GNU Lesser General Public License as published
      by the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU Lesser General Public License for more details.

      You should have received a copy of the GNU Lesser General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(Touche::ColaborativeManager *manager, QWidget *widget) :
    ui(new Ui::Dialog),
    manager(manager)
{
    ui->setupUi(this);
    QDialog::setParent(widget);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void Dialog::on_pushButton_clicked()
{
    if(!ui->edtEmail->text().isEmpty() && !ui->edtPassword->text().isEmpty()){
        namepass[0] = ui->edtEmail->text();
        namepass[1] = ui->edtPassword->text();
    }else{
        namepass[0] = "touche.compe";
        namepass[1] = "versaoumpontozero";
        //mensagem de erro \/
//        QMessageBox::information( this, tr("Efetuando Login"),tr("Os campos devem ser preenchidos para login. :D"),
//                                QMessageBox::Ok,
//                                QMessageBox::NoButton, QMessageBox::NoButton);

    }
    manager->connectToServer(namepass[0], namepass[1]);
    QDialog::accept();
    deleteLater();
}

void Dialog::on_cancelButton_clicked()
{
    QDialog::reject();
    deleteLater();
}
